<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>事件处理</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link href="<?php echo base_url()?>media/css/style.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/jquery.validate.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/handlers.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/check/CheckViewAgentForm.js"></script>
</head>
<body>
<div class="form_div" >
	<h5>SJ<?=sprintf("%08d", $eventId)?>:<?=htmlspecialchars($event['event_title'])?></h5>
		<div class="form_block black_border margin_t_b_5">
			<div class="input_item input_item_width140 margin_r_160" >
				<label>用户名&nbsp;&nbsp;</label>
				<input type="text" style="width:140px;float:left;" name="event_owner" value="<?php echo $event['event_owner'];?>" readonly="true" />
			</div>
			<div class="select_item">
				<label>用户类型</label>
				<select name="event_usertype" readonly="true">
					<?php foreach($event_usertype_list as $row):?>
                    <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_usertype']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                    <?php endforeach;?>
				</select>
			</div>
			<div class="input_item input_item_width140 margin_r_160">
				<label>公司部门</label>
				<input type="text" name="department" readonly="true" value="<?php echo $owner_info['department']; ?>" />
			</div>
			<div class="input_item" style="width:250px;">
				<label>联系电话</label>
				<input type="text" name="phone1" readonly="true" style="width:30px;"/>
				<input type="text" name="phone2" readonly="true"/> -
				<input type="text" name="phone3" readonly="true" style="width:30px;"/>
			</div>
			<div class="input_item input_item_width140 margin_r_160">
				<label>邮件地址</label>
				<input type="text" name="email" readonly="true" value="<?php echo $owner_info['email']; ?>"/>
			</div>
			<div class="input_item input_item_width140">
				<label>手机</label>
				<input type="text" name="mobile" readonly="true" />
			</div>
			<div class="input_item input_item_width500">
				<label>地址</label>
				<input type="text" name="address" readonly="true" />
			</div>
		<div class="clear_both"></div>
		</div>
		<div class="form_block black_border margin_t_b_5">
			<div class="input_item">
				<label>事件号</label>
				<input type="text" style="width:120px;" name="event_id" value="SJ<?php printf("%08d", $eventId);?>" readonly="true"/>
			</div>
			<div class="select_item">
				<label>请求类型</label>
				<select name="event_type" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
					<?php foreach($event_type_list as $row):?>
                    <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_type']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                    <?php endforeach;?>
				</select>
			</div>
			<div class="select_item">
				<label>状态</label>
				<select name="event_status" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
					<?php foreach($event_status_list as $row):?>
                    <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_status']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                    <?php endforeach;?>
				</select>
			</div>
			<div class="select_item">
				<label>紧急程度</label>
				<select name="event_emergency" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>> 
					<?php foreach($event_emergency_list  as $code=>$name):?>
                    <option value="<?php echo $code;?>" <?php if($code==$event['event_emergency']){echo "selected";}?>><?php echo $name;?></option>
                    <?php endforeach;?>
				</select>
			</div>
			<div class="select_item">
				<label>影响范围</label>
				<select name="event_influencearea" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
					<?php foreach($event_influencearea_list as $row):?>
                    <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_influencearea']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                    <?php endforeach;?>
				</select>
			</div>

			<!--div class="input_item margin_r_218">
				<label>影响开始时间</label>
				<input type="text" name="event_addtime" style="width:100px" value="<?php if($event['event_begintime']!='0000-00-00 00:00:00') echo $event['event_begintime'];?>" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?> />
			</div-->
			<div class="select_item">
				<label>来源</label>
				<select name="event_source" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
					<?php foreach($event_source_list as $row):?>
                    <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_source']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                    <?php endforeach;?>
				</select>
			</div>
					<div class="select_item margin_r_218">
						<label>类别</label>
						<select name="event_category" readonly="true">
							<?php foreach($event_cat_list as $row):?>
                            <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_category']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                            <?php endforeach;?>
						</select>
					</div>
					<div class="select_item">
						<label>子类</label>
						<select name="event_subclass" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
							<?php foreach($event_subclass as $row): ?>
                            <option value="<?=$row['option_id']?>" <?php if($row['option_id']==$event['event_subclass']){echo "selected";}?>><?=$row['option_name']?></option>
                            <?php endforeach; ?>
						</select>
					</div>
			<div class="input_item input_item_width500" >
				<label>主题</label>
				<input type="text" name="event_title" value="<?php echo htmlspecialchars($event['event_title']);?>" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>/>
			</div>
			<div class="textarea_item" >
				<label>描述</label>
				<textarea name="event_desc" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>><?php echo htmlspecialchars($event['event_desc']);?></textarea>
			</div>
				<div class="uploaded_file_info" style="padding-left:80px;clear:both;<?php if(count($event_attachments)>0): ?>height:40px;<?php endif;?>">
					<?php if (count($event_attachments)>0): ?>
		            <?php foreach($event_attachments as $row): ?>
					<?php if($row['attachment_isreply']==2): ?>
		            <div class="file_info"><a href="<?php echo base_url().$row['attachment_path'];?>"><?php echo $row['attachment_name'];?></a><!--span class='del_attach' aid='<?php echo $row['attachment_id'];?>'>X</span--></div>
					<?php endif; ?>
					<?php endforeach; ?>
					<?php endif; ?>
				</div>
			<div class="clear_both"></div>
			<div class="clear_both"></div>
		</div>
	<form method="post" action="<?php echo base_url()?>admin/forwardEvent/eventId/<?php echo $eventId;?>" onSubmit="return false;">
		<div class="form_block black_border margin_t_b_5">
			<div class="select_item margin_r_218">
				<label>工作组</label>
				<select name="group_id" id="group_charge" <?php if($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'";?> >
					<?php foreach($group_list as $row): ?>
                    <option value="<?=$row['group_id']?>" <?php if($row['group_id']==$event['event_groupid']){echo "selected";}elseif (!$event['event_groupid'] && $row['group_id']==4) echo "selected";?>><?=$row['group_name']?></option>
                    <?php endforeach; ?>
				</select>
			</div>
			<div class="input_item">
				<label>服务专员</label>
				<select name="event_charger" id="event_chargers" <?php if($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'";?> >
					<option value="0">请选择</option>
					<?php if(!empty($charger_list)): ?>
					<?php foreach($charger_list as $r): ?>
                    <option value="<?=$r['worker_name']?>" <?php if($r['worker_name']==$event['event_charger']){echo "selected";} elseif (empty($event['event_charger']) && $r['worker_name'] == $username) {echo "selected";}?>><?=$r['worker_name']?></option>
                    <?php endforeach; ?>
					<?php endif; ?>
				</select>
			</div>
			<div class="select_item">
				<label>优先级</label>
				<select name="event_priority" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
					<?php foreach($event_pri_list  as $code=>$name):?>
                    <option value="<?php echo $code;?>" <?php if($code==$event['event_priority']){echo "selected";}?>><?php echo $name;?></option>
                    <?php endforeach;?>
				</select>
			</div>
			<div class="input_item input_item_width500">
				<label>通报给</label>
				<input type="text" name="startTime" id="sendTo" value="<?php echo implode(";", options_helper::fieldDatas($charger_list, 'worker_name')); ?>" />
			</div>
			<div class="textarea_item" >
				<label>工作纪录</label>
				<textarea name="event_workrecord" readonly><?=$event['event_records']?></textarea>
			</div>
			<div class="textarea_item" >
				<label>工作说明</label>
				<textarea name="operate_content"></textarea>
			</div>
			<div class="textarea_item" >
				<label>解决办法</label>
				<textarea name="event_solution"></textarea>
			</div>
				<div id="uploaded_file_info2"  class="uploaded_file_info" style="padding-left:80px;clear:both;">
				</div>
				<div class="clear_both"></div>
			<div id="uploaded_file_info"  class="uploaded_file_info" style="padding-left:80px;clear:both;">
				<div id="fsUploadProgress"></div>
					<?php if (count($event_attachments)>0): ?>
		            <?php foreach($event_attachments as $row): ?>
					<?php if($row['attachment_isreply']==1): ?>
		            <div class="file_info"><a href="<?php echo base_url().$row['attachment_path'];?>"><?php echo $row['attachment_name'];?></a><!--span class='del_attach' aid='<?php echo $row['attachment_id'];?>'>X</span--></div>
					<?php endif; ?>
		            <?php endforeach; ?>
					<?php endif; ?>
			</div>
			<div class="clear_both"></div>
			<?php if($event['event_status'] != events_config::$event_status['EVENT_STATUS_CLOSE']): ?>
			<div class="upload_item">
				<label>附件</label>
				<span id="upload_btn"></span><input id="btnCancel" type="button" value="cancel" style="display:none;" />
			</div>
			<?php endif; ?>
			<div class="clear_both"></div>
		</div>
<?php if($event['event_status'] != events_config::$event_status['EVENT_STATUS_CLOSE']): ?>
		<div class="form_block black_border margin_t_b_5" style="text-align:center">
			<input type="submit" id="forwardEvent" class="sub_btn" value="转发" />
			<input type="reset" class="sub_btn" value="重置" />
   			<?php if($event['event_status']<events_config::$event_status['EVENT_STATUS_SOLUTION']):?>
            <input type="submit" id="finishEvent" class="sub_btn" value="处理完成" />
            <?php endif;?>
		</div>
<?php endif; ?>
	</form>
</div>
</body>
</html>
<script>
var swfu;
var settings = {
		flash_url : "<?=base_url()?>media/flash/swfupload.swf",
		upload_url: "<?=base_url()?>upload/uploadAttachment/eventId/<?php echo $eventId;?>/attachment_isreply/1",
		post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
		custom_settings : {
			progressTarget : "fsUploadProgress",
			cancelButtonId : "btnCancel",
			base_url:"<?=base_url()?>",
			uploadedFileInfoDiv:"uploaded_file_info"
		},
		debug: false,
		// Button settings
		button_image_url: "<?=base_url()?>media/images/upload_btn.gif"
	};
	swfu = new SWFUpload($.extend(settings,defaultSetting));
$(document).ready(function() {
	$(".del_attach").live('click',function(){
		var divObj = $(this);
		$.get('<?php echo base_url()?>upload/delAttachment/aid/'+divObj.attr('aid'),function(data){
			if(data=='success')
			{
				divObj.parent().fadeOut();
			}
		});
	});

	$("#event_chargers").change(function(){
		var username = "<?php echo $_SESSION['username']?>";
		if($(this).val() == username)
		{
			$("#forwardEvent").val('保存');
		}
		else
		{
			$("#forwardEvent").val('转发');
		}
	});
	$("#group_charge").change(function() {
		var group_id	= $(this).val();
		var url = "<?=base_url()?>group/getGroupMembersByGroupId";
		$.ajax({
			data: {group_id: group_id, s:Math.random()},
			dataType: 'json',
			type: 'post',
			url: url,
			success: function(ret) {
				var html = '<option value="0">请选择</option>';
				var sendTo = '';
				for (var i in ret) {
					html += '<option value="'+ret[i].worker_name+'">'+ret[i].worker_name+'</option>';
					sendTo += ret[i].worker_name + ';';
				}
				$("#event_chargers").html(html);
				$("#sendTo").val(sendTo);
			}
		});
	});

	$("#forwardEvent").click(function() {
		var operate_content = $.trim($("textarea[name='operate_content']").val());
		var url 			= "<?php echo base_url();?>admin/forwardEvent/eventId/<?=intval($eventId)?>";
		var event_groupid	= $("#group_charge").val();
		var event_charger	= $("#event_chargers").val();
		var event_priority	= $("select[name='event_priority']").val();
		if (event_groupid == '' || event_charger == '' || operate_content == '') {
			alert('工作组|负责人|工作说明不能为空');
			return false;
		}
		$.ajax({
			url: url,
			dataType:'json',
			data: {
				operate_content:operate_content,
				event_groupid: event_groupid,
				event_charger: event_charger,
				event_priority: event_priority
			},
			type: 'post',
			success: function(ret) {
				alert(ret.msg);
				if (!ret.success) {
					return false;
				} else {
					window.location.href = window.location.href;
					return false;
				}
			}
		});
		return false;
	});

	$("#processedEvents").click(function() {
		var operate_content = $("textarea[name='operate_content']").val();
		var url = "<?php echo base_url()?>event/updateEvents";
		var event_solution = $("textarea[name='event_solution']").val();

		$.ajax({
			url: url,
			dataType:'json',
			data: {
				operate_content:operate_content,
				eventId:<?php echo intval($eventId)?>,
				processed:1,
				s:Math.random,
				event_solution: event_solution,
				event_groupid: $("#group_charge").val(),
				event_charger: $("#event_chargers").val(),
				event_priority: $("select[name='event_priority']").val(),
				raw_record: $("textarea[name='event_workrecord']").val()
			},
			type: 'post',
			success: function(ret) {
				alert(ret.msg);
				window.location.href = window.location.href;
			}
		});
		return false;
	});

	$("#finishEvent").click(function(){
		var event_solution	= $.trim($("textarea[name='event_solution']").val());
		var url = "<?php echo base_url();?>admin/finishEvent";

		if (event_solution == '') {
			alert('解决方案不能为空');
			return false;
		}
		$.ajax({
			url: url,
			dataType: 'json',
			data: {
				eventId: <?php echo $eventId;?>,
				event_solution: event_solution
			},
			type: 'post',
			success: function(ret) {
				alert(ret.msg);
				if (ret.success) {
					window.location.href=window.location.href;
				} else {
					return false;
				}	
			}
		});
	});
});

</script>
